package com.hmy.common.exception;


import java.io.Serializable;

public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data;
    private Boolean status;

    public Result(int code, String msg, Object data, Boolean status) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.status = status;
    }

    public static Result succeed() {
        return succeed(null);
    }

    public static Result succeed(Object data) {
        return getResult(ResultEnum.SUCCEED, data, true);
    }

    public static Result error() {
        return error(ResultEnum.ERROR);
    }

    public static Result error(ResultEnum ResultEnum) {
        return getResult(ResultEnum, null, false);
    }

    public static Result error(String errorMessage) {
        return error(ResultEnum.ERROR.getCode(), errorMessage);
    }

    public static Result error(int code, String errorMessage) {
        return new Result(code, errorMessage, null, false);
    }

    private static Result getResult(ResultEnum ResultEnum, Object data, Boolean status) {
        return new Result(ResultEnum.getCode(), ResultEnum.getMsg(), data, status);
    }

    public static Result getBooleanResult(Boolean status) {
        if (status) {
            return getResult(ResultEnum.SUCCEED, null, true);
        }
        return getResult(ResultEnum.ERROR, null, false);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }
}
